package com.bdth.service.impl;

import com.bdth.controller.AlarmController;
import com.bdth.mapper.GPSRealDataMapper;
import com.bdth.model.GPSRealData;
import com.bdth.model.User;
import com.bdth.service.IRealDataService;
import com.bdth.utils.JacksonUtils;
import com.bdth.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: 徐斌
 * @Date: 2018-04-12 10:34
 */
@Service
public class RealDataServiceImpl extends BaseServiceImpl<GPSRealData> implements IRealDataService {


	protected static final Logger logger = LoggerFactory.getLogger(RealDataServiceImpl.class);

	@Autowired
	private GPSRealDataMapper mapper;

	@Autowired
	private RedisTemplate redisTemplate;

	@Override
	public List<GPSRealData> getRealDataList(List<String> simNoList) {
		List<GPSRealData> gpsRealDataList = new ArrayList<GPSRealData>();
		ValueOperations<String, String> stringOperations = redisTemplate
				.opsForValue();
		//stringOperations.setIfAbsent("json", "{\"userName\":\"JSON\",\"loginName\":\"测试\",\"passWord\":\"JSON\"}");
	/*	for (String simNo : simNoList) {
			String value = stringOperations.get(simNo);
			System.out.println(value);
		}*/
		try {
			List<String> list = stringOperations.multiGet(simNoList);
			for (String st : list) {
				if (!StringUtil.isEmptyWithNullStr(st)) {
					GPSRealData gpsRealData = JacksonUtils.json2pojo(st, GPSRealData.class);
					gpsRealDataList.add(gpsRealData);
				}
			}

		} catch (Exception ex) {
			logger.error(ex.getMessage());
		}


/*		try {
			String json = stringOperations.get("json");
			User user = JacksonUtils.json2pojo(json, User.class);
			System.out.println(json);
		} catch (Exception ex) {

		}*/

		//List<GPSRealData> gpsRealDataList = mapper.queryByMapList(map);

/*		try {
			User user = new User();
			user.setUserName("test");
			user.setLoginName("test");
			stringOperations.setIfAbsent("test", JacksonUtils.obj2json(user));
		} catch (Exception ex) {

		}*/
		return gpsRealDataList;
	}

	@Override
	public List<GPSRealData> getOnlineRealDataList() {
		List<GPSRealData> gpsRealDataList = new ArrayList<GPSRealData>();

		return gpsRealDataList;
	}

	@Override
	public GPSRealData get(String simNo) {
		ValueOperations<String, String> stringOperations = redisTemplate
				.opsForValue();
		GPSRealData gpsRealData = new GPSRealData();
		try {
			String json = stringOperations.get(simNo);
			gpsRealData = JacksonUtils.json2pojo(json, GPSRealData.class);

		} catch (Exception ex) {
			logger.error(ex.getMessage());
		}
		return gpsRealData;
	}

}
